<?php

include 'load.php';

$rss_tasks = $snsdb->get_results('select * from sns_rss_task');

print_r($rss_tasks);

foreach($rss_tasks as $rss_task){
	needPublish($rss_task);
}


function needPublish($rss_task){
	$regularly = $rss_task->forward_regularly;
	$lasttime = $rss_task->last_forward_time;
	$regularlies = explode(' ', $regularly);
	if(checkRegularly($regularlies)){
		echo "=====================";
	}
	print_r($regularlies);
}

function checkRegularly($regularlies){
	if (count($regularlies) != 5){
		return false;
	}else{
		$min = false;
		$hor = false;
		$day = false;
		$mon = false;
		$wee = false;
		if(preg_match('/\*/', $regularlies[0]) ||  preg_match('/\*\/[1-60]/', $regularlies[0]) 
			&& preg_match('/[0-60]-[0-60]/', $regularlies[0]) && preg_match('/[0-60]-[0-60]\/[0-60]/', $regularlies[0])){
				$min = true;
			}
		
		if(preg_match('/\*/', $regularlies[1]) ||  preg_match('/\*\/[1-24]/', $regularlies[1]) 
			&& preg_match('/[0-24]-[0-24]/', $regularlies[1]) && preg_match('/[0-24]-[0-24]\/[0-24]/', $regularlies[1])){
				$hor = true;
			}
			
		if(preg_match('/\*/', $regularlies[2]) ||  preg_match('/\*\/[1-31]/', $regularlies[2]) 
			&& preg_match('/[0-31]-[0-31]/', $regularlies[2]) && preg_match('/[0-31]-[0-31]\/[0-31]/', $regularlies[2])){
				$day = true;
			}
		
		if(preg_match('/\*/', $regularlies[3]) ||  preg_match('/\*\/[1-12]/', $regularlies[3]) 
			&& preg_match('/[0-12]-[0-12]/', $regularlies[3]) && preg_match('/[0-12]-[0-12]\/[0-12]/', $regularlies[3])){
				$mon = true;
			}
			
		if(preg_match('/\*/', $regularlies[4]) ||  preg_match('/\*\/[0-6]+/', $regularlies[4]) 
			&& preg_match('/[0-6]-[0-6]/', $regularlies[4]) && preg_match('/[0-6]-[0-6]\/[0-6]/', $regularlies[4])){
				$wee = true;
			}
			
		return $min && $hor && $day && $mon && $wee;
	}
}

?>